home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual BASIC 5.0 (Ent. Edition) / Vb5ent Extractor.EXE / VB / SAMPLES / ENTRPRIS / APE / AEPOOL / POOL.CLS < prev    next >
Encoding:
Visual Basic class definition  |  1996-12-04  |  4.6 KB  |  126 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "Pool"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = True
  10. Attribute VB_Description = "Provides an interface for clients to request and release AEWorker.Worker objects."
  11. Option Explicit
  12. 'Private variable to hold the WorkerID of the Worker which was
  13. 'passed to a client
  14. Private mlWorkerID As Long
  15. 'A count of references is kept to keep track of
  16. 'how many references to this same worker it has.
  17. 'When the count is 0, moWorker is added back into
  18. 'the global collection and set to nothing.
  19. Private mlReferenceCount As Long
  20.  
  21. Private Sub Class_Initialize()
  22.     CountInitialize
  23. End Sub
  24.  
  25. Private Sub Class_Terminate()
  26.     CountTerminate
  27. End Sub
  28.  
  29. Public Function GetWorker() As AEWorker.Worker
  30. Attribute GetWorker.VB_Description = "Returns a AEWorker.Worker object and reserves it for the calling applications use."
  31.     'A client uses this method to get a reference to a worker
  32.     'Find a worker that is not busy (passed to another client).
  33.     'Mark the Worker as busy
  34.     'Store the WorkerID in the Private Class Module level
  35.     'mlWorkerID
  36.     Dim oWork As clsWorker
  37.     Dim bFoundWorker As Boolean
  38.     On Error GoTo GetWorkerError
  39.     LogEvent giGET_WORKER
  40.     'If mlWorkerID does not equal zero then the client
  41.     'that has reference to this instance of this class
  42.     'already has a worker.  Therefore just pass a reference
  43.     'to the same worker.
  44.     If mlWorkerID <> 0 Then
  45.         mlReferenceCount = mlReferenceCount + 1
  46.         Set GetWorker = gcWorkers.Item(CStr(mlWorkerID)).Worker
  47.         glRequestsSatisfied = glRequestsSatisfied + 1
  48.         If gbShow Then
  49.             With frmPoolMgr.lblSatisfied
  50.                 .Caption = CStr(glRequestsSatisfied)
  51.                 .Refresh
  52.             End With
  53.         End If
  54.     Else
  55.         'The client does not have any other references to a Worker
  56.         'Find a worker that does not have any connections made
  57.         'by other clients
  58.         bFoundWorker = False
  59.         For Each oWork In gcWorkers
  60.             If Not oWork.Busy Then
  61.                 oWork.Busy = True
  62.                 mlWorkerID = oWork.ID
  63.                 mlReferenceCount = mlReferenceCount + 1
  64.                 bFoundWorker = True
  65.                 Set GetWorker = oWork.Worker
  66.                 'Update statistics
  67.                 glRequestsSatisfied = glRequestsSatisfied + 1
  68.                 If gbShow Then
  69.                     With frmPoolMgr.lblSatisfied
  70.                         .Caption = CStr(glRequestsSatisfied)
  71.                         .Refresh
  72.                     End With
  73.                 End If
  74.                 Exit For
  75.             End If
  76.         Next oWork
  77.         If Not bFoundWorker Then
  78.             'All workers are being used by other clients
  79.             'set function equal to nothing
  80.             Set GetWorker = Nothing
  81.             glRequestsRejected = glRequestsRejected + 1
  82.             If gbShow Then
  83.                 With frmPoolMgr.lblRejected
  84.                     .Caption = CStr(glRequestsRejected)
  85.                     .Refresh
  86.                 End With
  87.             End If
  88.         End If
  89.     End If
  90.     Exit Function
  91. GetWorkerError:
  92.     Select Case Err.Number
  93.         Case ERR_OVER_FLOW
  94.             LogError Err
  95.             If glRequestsSatisfied = glMAX_LONG Then glRequestsSatisfied = 0
  96.             If glRequestsRejected = glMAX_LONG Then glRequestsRejected = 0
  97.             Resume Next
  98.         Case Else
  99.             LogError Err
  100.             Err.Raise Err.Number, Err.Source, Err.Description
  101.     End Select
  102. End Function
  103.  
  104. Public Sub ReleaseWorker()
  105. Attribute ReleaseWorker.VB_Description = "Notifies the AEPoolMgr that an AEWorker.Worker object received by GetWorker is no longer referenced by the calling application."
  106.     'Called by a client when it destroys a reference to
  107.     'a worker that it received by calling GetWorker
  108.     'Check to see if the client has another reference to
  109.     'the worker.  If it does not, mark the worker that was passed
  110.     'to the client as not busy and set mlWorkerID = to 0.
  111.     LogEvent giRELEASE_WORKER
  112.     'If ReferenceCount is zero then this method is being called without
  113.     'having an unreleased reference to the worker
  114.     If mlReferenceCount = 0 Then Exit Sub
  115.     mlReferenceCount = mlReferenceCount - 1
  116.     'If ReferenceCount = 0 now then client has released
  117.     'its only reference to a worker
  118.     If mlReferenceCount = 0 Then
  119.         gcWorkers.Item(CStr(mlWorkerID)).Busy = False
  120.         mlWorkerID = 0
  121.     End If
  122. End Sub
  123.  
  124.  
  125.  
  126.